package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation(value = "分页查询接口")
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(value = "护理项名称",name = "name" ,dataType = "string"),
            @ApiImplicitParam(value = "启用状态",name = "status" ,dataType = "string"),
            @ApiImplicitParam(value = "页码",name = "pageNum",required = true,dataType = "int"),
            @ApiImplicitParam(value = "每页显示条数",name = "pageSize",required = true,dataType = "int")
    })
    public ResponseResult selectByPage(String name, Integer status,
                                       Integer pageNum, Integer pageSize) {
        PageResponse page = nursingProjectService.selectByPage(name, status, pageNum, pageSize);
        return success(page);
    }

    @ApiOperation(value = "新增护理项接口")
    @PostMapping
    public ResponseResult save(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insertNursingProject(nursingProjectDto);
        return success();
    }

    @ApiOperation(value = "根据id查询护理项接口")
    @GetMapping("/{id}")
    public ResponseResult selectById(@PathVariable Integer id){
        NursingProjectVo nursingProjectVo = nursingProjectService.selectById(id);
        return success(nursingProjectVo);
    }

    @ApiOperation("修改护理项接口")
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }
}
